<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24">
        <blockquote class="text-warning" style="font-size: 14px">
          <h2 style="text-align: center;"><strong>满江红·写怀</strong></h2>
          <br>
          <h5 style="text-align: center">岳飞·宋</h5>
          <h4 style="text-align: start;">
            怒发冲冠，凭栏处、潇潇雨歇。抬望眼、仰天长啸，壮怀激烈。三十功名尘与土，八千里路云和月。莫等闲、白了少年头，空悲切。
            靖康耻，犹未雪。臣子恨，何时灭。驾长车，踏破贺兰山缺。壮志饥餐胡虏肉，笑谈渴饮匈奴血。待从头、收拾旧山河，朝天阙。</h4>
        </blockquote>
        <hr>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24">
        <el-table
          :data="thisYearMedals"
          style="width: 100%;margin-left: 20px; color: #409EFF;"
          max-height="250"
          :row-class-name="tableRowClassName"
        >
          <el-table-column
            v-if="isShow"
            prop="isChina"
            label="国家/地区"
            width="200"
          />
          <el-table-column
            fixed="left"
            prop="countryName"
            label="国家/地区"
            width="200"
          />
          <el-table-column
            label="国家/地区(代码)"
            width="200"
          >
            <template slot-scope="scope">
              <div style="cursor: pointer;" @click="navigateToExternalLink(scope.row.link)">
                <img :src="scope.row.countryFlag" alt="国家国旗" style="width: 20%; height: auto;">
                {{ scope.row.countryAbbr }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="排名"
            width="150"
          >
            <template slot-scope="scope">
              第{{ scope.row.rank }}名
            </template>
          </el-table-column>
          <el-table-column
            label="金牌数量"
            width="150"
          >
            <template slot-scope="scope">
              <span style="color: #EFC727;">{{ scope.row.gold }}枚</span>
            </template>
          </el-table-column>
          <el-table-column
            label="银牌数量"
            width="150"
          >
            <template slot-scope="scope">
              <span style="color: #BABCB9;">{{ scope.row.silver }}枚</span>
            </template>
          </el-table-column>
          <el-table-column
            label="铜牌数量"
            width="150"
          >
            <template slot-scope="scope">
              <span style="color: #BE8D24;">{{ scope.row.bronze }}枚</span>
            </template>
          </el-table-column>
          <el-table-column
            label="总计"
            width="150"
          >
            <template slot-scope="scope">
              <span style="color: #BE8D24;">{{ scope.row.total }}枚</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="详情"
            width="100"
          >
            <template slot-scope="scope">
              <span
                style="color: #409EFF; cursor: pointer;"
                @click="showDetailDialog(scope.row)"
              >详情</span>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :sm="24" :lg="8" style="padding-left: 20px">
        <h2>墓志铭</h2>
        <p>
          在这片宁静的土地之下，我安然长眠，与岁月共融，化作尘埃，归于无垠。回顾往昔，我以勤勉织就人生华章，以善良温暖世间角落。风雨兼程中，我笑对挑战，云淡风轻处，我悠然自得。不求生前身后名，但愿留下的每一份努力与温暖，能如星辰般照亮他人之路。在此安息，愿世界因我曾来过而更加美好，灵魂得以超越时空，获得永恒的宁静与自由。        </p>
        <p>
          <b>当前版本:</b> <span>v{{ version }}</span>
        </p>
        <p>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-cloudy"
            plain
            @click="goTarget('https://gitee.com/zhangkun11/oauth2-cloud')"
          >访问码云</el-button>
          <el-button
            size="mini"
            icon="el-icon-s-home"
            plain
            @click="goTarget('https://gitee.com/zhangkun11')"
          >访问主页</el-button>
        </p>
      </el-col>
      <el-col :sm="24" :lg="16" style="padding-right: 20px">
        <el-row style="text-align: center;">
          <el-col :span="24">
            <h2>网易云热评</h2>
          </el-col>
        </el-row>
        <el-carousel :interval="4000" type="card" height="150px" arrow="never" indicator-position="none">
          <el-carousel-item v-for="(item,index) in hotComments" :key="index">
            <el-col>
              <div style="text-align: center;margin-top: 10px;">
                <h4>{{ item.nickname }}</h4>
              </div>
              <ul class="list">
                <li>{{ item.content }}</li>
                <div style="float: right;">
                  <font-awesome-icon :icon="['fas', 'thumbs-up']" beat-fade style="color: darkorange; margin-right: 8px;" />
                  {{ item.likedCount }}
                </div>
              </ul>
            </el-col>
          </el-carousel-item>
        </el-carousel>
      </el-col>
    </el-row>
    <el-divider />
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>用户信息</span>
          </div>
          <div class="body">
            <p>
              <i class="el-icon-s-promotion" /> Gitee:<el-link
                href="https://gitee.com/zhangkun11"
                target="_blank"
              >https://gitee.com/zhangkun11</el-link>
            </p>
            <p>
              <i class="el-icon-user-solid" /> QQ <a href="https://user.qzone.qq.com/3185200686/infocenter" target="_blank">3185200686</a>
            </p>
            <p>
              <i class="el-icon-chat-dot-round" /> WeChat<a
                href="javascript:;"
              >/ 18184273025</a>
            </p>
            <p>
              <i class="el-icon-money" /> 支付宝：<a
                href="javascript:;"
                class="支付宝信息"
              >/ 18184273025</a>
            </p>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>历届奥运会</span>
          </div>
          <div v-for="o in seasonList" :key="o" class="text item">
            {{ o }}
          </div>
        </el-card>

      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>我的头像</span>
          </div>
          <div class="body">
            <img
              src="@/assets/images/anl.jpg"
              alt="donate"
              width="80%"
            >
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 详情对话框 -->
    <el-dialog
      title="详情"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <div>
        <img :src="detailData.countryFlag" alt="国家国旗" style="width: 25%; height: auto;">
      </div>
      <div class="dialog-content">
        <div class="info-group">
          <div class="label">国家/地区:</div>
          <div class="value" style="font-size: 18px; margin-top: 2px;margin-right: 100px;">{{ detailData.countryName }}</div>
          <div class="label">国家/地区(代码):</div>
          <div class="value">{{ detailData.countryAbbr }}</div>
        </div>
        <div class="medal-counts">
          <div class="medal-count" style="color: gold; ">
            <div class="label">金牌数量:</div>
            <div class="value">{{ detailData.gold }}枚</div>
          </div>
          <div class="medal-count" style="color: silver; ">
            <div class="label">银牌数量:</div>
            <div class="value">{{ detailData.silver }}枚</div>
          </div>
          <div class="medal-count" style="color: #cd7f32; "> <!-- 铜牌常用色 #cd7f32 -->
            <div class="label">铜牌数量:</div>
            <div class="value">{{ detailData.bronze }}枚</div>
          </div>
        </div>
        <div class="total-count">
          <div class="label">总计:</div>
          <div class="value" style="font-size: 16px;">{{ detailData.total }}枚</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getHotComments, getMedalInfo } from '@/api/interface'
export default {
  name: 'Index',
  data() {
    return {
      // 版本号
      hotComments: [
        {
          nickname: '数据加载中...',
          content: '数据加载中...',
          likedCount: 0
        }
      ],
      medalList: [],
      thisYearMedals: [],
      seasonList: [],
      detailData: {},
      isShow: false,
      dialogVisible: false,
      version: '1.0.0'
    }
  },
  mounted() {
    this.initReview()
  },
  methods: {
    initReview() {
      getHotComments().then(resp => {
        this.hotComments = resp.data
      })
      getMedalInfo().then(resp => {
        this.medalList = resp.data.medalList
        this.thisYearMedals = this.medalList[0]
        this.seasonList = resp.data.seasonList
      })
    },
    goTarget(href) {
      window.open(href, '_blank')
    },
    navigateToExternalLink(url) {
      window.location.href = 'https://tiyu.baidu.com' + url
    },
    tableRowClassName({ row, rowIndex }) {
      // 如果isChina为1，则返回一个类名，否则返回空字符串
      if (row.isChina === 1) {
        return 'highlight-row'
      }
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },
    showDetailDialog(row) {
      this.detailData = { ...row } // 复制当前行数据到detailData
      this.dialogVisible = true // 显示对话框
    }
  }
}
</script>
<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin-top: 0;
  }
  .el-carousel__item:nth-child(2n) {
    background-color: #ffffff;
  }
  .el-carousel__item:nth-child(2n+1) {
    background-color: rgba(244, 243, 243, 0.784)  }
  .list {
  list-style: none; /* 移除默认的列表样式 */
  padding: 0; /* 移除默认的padding */
  }
  .list li {
  height: 90px; /* 防止文本换行 */
  overflow: hidden; /* 隐藏超出部分 */
  text-overflow: ellipsis; /* 超出部分用省略号代替 */
  /* 你可以添加一些其他的样式，比如padding, margin, border等 */
  padding: 15px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  margin-bottom: 2px;
  }
  .el-table .highlight-row {
    color: #409EFF;
  }
  .el-table .warning-row {
    color: #409EFF;
  }

  .el-table .success-row {
    color: #409EFF;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }
  .dialog-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px; /* 增加元素间的间距 */
}

.info-group, .medal-counts, .total-count {
  display: flex;
  align-items: center;
  margin: 2px;
  gap: 8px; /* 标签与值之间的间距 */
}
.medal-count{
  display: flex;
  margin-left: 20px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.label {
  font-weight: bold;
}

.value {
  font-size: 14px; /* 默认字体大小 */
}

/* 单独调整国家/地区名称的字体大小 */
.info-group:first-child .value {
  font-size: 18px;
}

.dialog-footer {
  text-align: right;
  padding: 10px 20px;
}
</style>

